package org.example.conrtoller;

import org.example.Imp.TeacherServiceImp;
import org.example.domain.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpSession;


@Controller
public class LoginControllerT {
    @Autowired
    private TeacherServiceImp teacherServiceImp;
    @RequestMapping("/loginT.html")
    public String login(){
        return "t_login_page";
    }
    @ResponseBody
    @RequestMapping("/common/loginVerifyT")
    public String loginVerify(Teacher teacher, HttpSession httpSession){
        Teacher temp = teacherServiceImp.selectOneTeacherByMnemonic_code(teacher.getMnemonic_code());
        if (temp==null){
            return "1";//"账号不存在"
        }
        if (teacherServiceImp.judgePassword(temp.getPass(),teacher.getPass())){
            //登录成功  存储信息到session中 后续要用
            httpSession.setAttribute("loginTeacher",temp);
            return "0";//"密码正确"
        }
        return "1";//"密码错误"
    }
    @RequestMapping("/mainPageT.html")
    public String mainPage(){
        return "mainPage";
    }
    @RequestMapping("/timeoutT")
    public String timeout(){
        return "common/visitTimeOut";
    }
}